﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CoursePack;
using Scheduler;

namespace TheSchedulator.UserControls
{
    public delegate void RemoveCourseChoice(object sender, EventArgs e);

    public partial class CourseChoice : UserControl
    {
        #region Data
        CourseChoiceInfo m_courseChoiceInfo;
        public event RemoveCourseChoice OnRemoveCourse;
        private string m_CourseName;
        private float m_Credits;
        private TreeNode m_Courses;
        #endregion

        public CourseChoice(TreeNode _Courses)
        {
            InitializeComponent();
            this.m_Courses = _Courses;
            List<Course> tmp = new List<Course>();

            foreach (TreeNode cc in _Courses.Nodes)
            {
                tmp.Add((Course)cc.Tag);
            }

            this.m_CourseName = tmp[0].ToString();
            this.m_Credits = tmp[0].Credits;
            this.m_courseChoiceInfo = new CourseChoiceInfo(tmp);        
        }

        private void CourseChoice_Load(object sender, EventArgs e)
        {
            Course c = null;
            foreach (Course cc in this.m_courseChoiceInfo.Courses)
            {

                if (!this.comboBox1.Items.Contains(cc.Lecture.Professor))
                {
                    this.comboBox1.Items.Add(cc.Lecture.Professor);
                    c = cc;
                }
            }

            this.lblTitle.Text = c.ToString() + "   " + c.CourseTitle;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.m_courseChoiceInfo.TeacherPreference = this.comboBox1.SelectedItem.ToString();
        }

        private void splitContainer1_Panel1_MouseMove(object sender, MouseEventArgs e)
        {
            this.lblTitle.BackColor = this.button1.ForeColor;
        }

        private void splitContainer1_Panel1_MouseLeave(object sender, EventArgs e)
        {
            this.lblTitle.BackColor = Color.Black;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.OnRemoveCourse != null)
                this.OnRemoveCourse(this, e);
        }

        #region Accessors
        public CourseChoiceInfo Courses
        {
            get { return this.m_courseChoiceInfo; }
        }

        public TreeNode Course
        {
            get { return this.m_Courses; }
        }

        public string CourseName 
        {
            get { return this.m_CourseName; }
        }

        public float Credits
        {
            get { return this.m_Credits; }
        }
        #endregion
    }
}
